﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Services.Protocols;

namespace Codeplex.CRMQuery.UnitTest
{
    public static class CrmHelper
    {
        /// <summary>
        /// Get a Connection to the CRM Service
        /// </summary>
        /// <returns></returns>
        public static Microsoft.Crm.SdkTypeProxy.CrmService GetCrmService()
        {
            Microsoft.Crm.Sdk.CrmAuthenticationToken token = new Microsoft.Crm.Sdk.CrmAuthenticationToken();
            token.OrganizationName = Properties.Settings.Default.CrmOrganizationName;
            token.AuthenticationType = 0; // Authentication Type Active Directory

            Microsoft.Crm.SdkTypeProxy.CrmService service = new Microsoft.Crm.SdkTypeProxy.CrmService();
            service.Url = Properties.Settings.Default.CrmServiceURL;
            service.CrmAuthenticationTokenValue = token;
            service.UseDefaultCredentials = true;

            return service;
        }

        /// <summary>
        /// Get a Connection to the CRM Metadata Service
        /// </summary>
        /// <returns></returns>
        public static Microsoft.Crm.SdkTypeProxy.Metadata.MetadataService GetCrmMetadataService()
        {
            Microsoft.Crm.Sdk.CrmAuthenticationToken token = new Microsoft.Crm.Sdk.CrmAuthenticationToken();
            token.OrganizationName = Properties.Settings.Default.CrmOrganizationName;
            token.AuthenticationType = 0; // Authentication Type Active Directory

            Microsoft.Crm.SdkTypeProxy.Metadata.MetadataService service = new Microsoft.Crm.SdkTypeProxy.Metadata.MetadataService();
            service.Url = Properties.Settings.Default.CrmMetadataServiceURL;
            service.CrmAuthenticationTokenValue = token;
            service.UseDefaultCredentials = true;

            return service;
        }
    }
}